package com.aiyige.page.my.message.notifymessage.commentmessage.adapter;

import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.page.my.message.notifymessage.commentmessage.model.CommentMessage;
import com.aiyige.page.my.message.util.MessageUtil;
import com.aiyige.utils.DateFormatUtil;
import com.aiyige.utils.StringUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.vondear.rxtools.RxTextTool;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.CropCircleTransformation;

/**
 * Created by zhuyakun on 2017/8/14.
 */

public class CommentMessageAdapter extends BaseQuickAdapter<CommentMessage, CommentMessageAdapter.ViewHolder> {


    public CommentMessageAdapter() {
        super(R.layout.comment_message_item, new LinkedList<CommentMessage>());
    }

    @Override
    protected void convert(ViewHolder helper, CommentMessage data) {
        helper.bindData(data);
    }

    public static class ViewHolder extends BaseViewHolder {
        @BindView(R.id.otherHeadIv)
        ImageView otherHeadIv;
        @BindView(R.id.otherNameTv)
        TextView otherNameTv;
        @BindView(R.id.otherTimeTv)
        TextView otherTimeTv;
        @BindView(R.id.otherCommentMessageTv)
        TextView otherCommentMessageTv;
        @BindView(R.id.myCommentTv)
        TextView myCommentTv;
        @BindView(R.id.coverIv)
        ImageView coverIv;
        @BindView(R.id.mediaReleaseDateTv)
        TextView mediaReleaseDateTv;
        @BindView(R.id.mediaTitleTv)
        TextView mediaTitleTv;
        @BindView(R.id.playIv)
        ImageView playIv;
        @BindView(R.id.myLayout)
        View myLayout;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            addOnClickListener(R.id.otherHeadIv);
            addOnClickListener(R.id.otherNameTv);
            addOnClickListener(R.id.replyBtn);
        }

        public void bindData(CommentMessage data) {
            otherNameTv.setText(data.getOtherName());
            Glide.with(itemView.getContext())
                    .load(data.getOtherAvatar())
                    .apply(RequestOptions.placeholderOf(android.R.color.white))
                    .apply(RequestOptions.circleCropTransform())
                    .into(otherHeadIv);

            Glide.with(itemView.getContext())
                    .load(data.getCover())
                    .apply(RequestOptions.placeholderOf(android.R.color.white))
                    .into(coverIv);

            otherTimeTv.setText(DateFormatUtil.getStandardDate(data.getOtherTime()));
            mediaTitleTv.setText(data.getMediaTitle());
            mediaReleaseDateTv.setText(DateFormatUtil.formatMS("yyyy-MM-dd", data.getMediaReleaseDate()));
            playIv.setVisibility(data.getTargetType() == MessageUtil.TARGET_TYPE_VIDEO || data.getTargetType() == MessageUtil.TARGET_TYPE_LEARN_VIDEO? View.VISIBLE : View.INVISIBLE);
            switch (data.getTargetType()) {
                case MessageUtil.TARGET_TYPE_COMMENT: {
                    myLayout.setVisibility(View.VISIBLE);
                    RxTextTool.getBuilder("")
                            .append(data.getMyName() + ": ").setForegroundColor(0xFF909090).setProportion(1.1f)
                            .append(data.getMyComment()).setForegroundColor(0xFF606060)
                            .into(myCommentTv);
                    RxTextTool.getBuilder("")
                            .append(StringUtils.getString(R.string.other_reply)).setForegroundColor(0xFF909090).setProportion(1.1f)
                            .append(data.getOtherComment()).setForegroundColor(0xFF333333)
                            .into(otherCommentMessageTv);
                    break;
                }
                default: {
                    myLayout.setVisibility(View.GONE);
                    RxTextTool.getBuilder("")
                            .append(StringUtils.getString(R.string.other_comment)).setForegroundColor(0xFF909090).setProportion(1.1f)
                            .append(data.getOtherComment()).setForegroundColor(0xFF333333)
                            .into(otherCommentMessageTv);
                    break;
                }
            }
        }
    }
}
